﻿using System.Windows.Controls;
using Agnes.Core;
using DevExpress.XtraRichEdit;

namespace Agnes.MyDocsLib
{
    /// <summary>
    /// ArticleView.xaml 的交互逻辑
    /// </summary>
    public partial class ArticleView : UserControl
    {
        public ArticleView()
        {
            InitializeComponent();
            recRichEdit.GotFocus += (sender, args) =>
                                        {
                                            AgnesServiceManager.AgnesWorkBenchService.FocusedRichEditControl =
                                                recRichEdit;
                                        };
            this.DataContextChanged += (sender, args) =>
                                           {
                                               recRichEdit.ReadOnly = !(this.DataContext as ArticleViewModel).IsEditMode;
                                               (this.DataContext as ArticleViewModel).PropertyChanged +=
                                                   (o, eventArgs) =>
                                                       {
                                                           if (eventArgs.PropertyName == "IsEditMode")
                                                           {
                                                               recRichEdit.ReadOnly =
                                                                   !(this.DataContext as ArticleViewModel).IsEditMode;
                                                           }
                                                       };
                                           };

            this.LostFocus += (sender, args) =>
                                  {
                                      AgnesServiceManager.AgnesWorkBenchService.FocusedDocumentPanel = null;
                                  };

            this.GotFocus += (sender, args) =>
                                 {
                                     AgnesServiceManager.AgnesWorkBenchService.FocusedDocumentPanel =
                                         this.DataContext as IDocumentPanel;

                                 };
            this.recRichEdit.RtfTextChanged += (sender, args) =>
                                                   {
                                                       (this.DataContext as ArticleViewModel).Model.MakeDirty();
                                                   };
        }


  
    }
}
